import time,copy
import random
import math


import zlib

"""本模块非开发者本人,禁止改动!!"""

def int_to_bytes(n:int):
    if not n:
        return [0]
    binary_str =bin(n)[2:].zfill((len(bin(n)[2:]) + 7) // 7* 7)
    binary_str = [binary_str[i:i + 7] for i in range(0, len(binary_str), 7)]
    byteList = []
    if not int(binary_str[0],2):
        binary_str.remove(binary_str[0])
    for b,_byte in enumerate(binary_str):
        _byte = int('0' + _byte,2)  if not b  else  int('1' + _byte,2)
        byteList.append(_byte)
    byteList.reverse()
    return byteList
def butget(t=0,e=0):
    if t == 64:
        return 64
    elif t == 63:
        return e
    elif t >= e:
        return t + 1
    else:
        return t
class PDD_Cracking:
    def __init__(self):
        self.V = '9240gsB6PftGXnlQTw_pdvz7EekDmuAWCVZ5UF-MSK1IHOchoaxqYyj8Jb3LrNiR='
        self.d = {'_bK': 0}
        self.h = {'_xea': [v for v in self.V],
             '_bÌ': 64,
             }
    def StartTask(self,data):
        self.t = data
        self.T = self.handler_data()
        anti_content = self.PDD_encode()
        return anti_content
    def p_(self):
        compressed = zlib.compress(bytes(self.t))
        return compressed
    def handler_data(self):
        P = self.p_()
        decompressed_list = bytearray(P)
        new_arr = [int(byte)  for byte in decompressed_list]
        new_h = [chr(i) for  i  in new_arr] + ['£', 'ø', 'C', 'E']
        h2 = ''.join(new_h)
        return  h2
    def isNaN(self,value):
        if isinstance(value, (int, float)):
            return math.isnan(value)
        elif isinstance(value, str):
            try:
                float(value)
                return False
            except ValueError:
                return True
        elif isinstance(value, list):
            if len(value) != 1:
                return True
            else:
                try:
                    float(value[0])
                    return False
                except ValueError:
                    return True
        else:
            return True
    #h
    def _xe1(self,t):
        self.h['_bÌ'] += 1
        if  len(self.h['_xea']) <= self.h['_bÌ']:
            self.h['_xea'].append(t)
        else:
            self.h['_xea'][self.h['_bÌ']] = t
    #d
    def _bf(self):
        try:
            char_code = ord(self.d['_bÇ'][self.d['_bK']])
        except:
            char_code = 0
        self.d['_bK'] += 1
        return char_code
    def PDD_encode(self):
        P = ""
        y = int(random.random()*64)
        self.d['_bÇ'] = self.T
        GG =  0
        while self.d['_bK'] < len(self.T):
            GG+=1
            self._xe1(self._bf())
            self._xe1(self._bf())
            self._xe1(self._bf())
            i = int(self.h['_xea'][self.h['_bÌ']-2]) >> 2
            a0 = int(self.h['_xea'][(self.h['_bÌ']-2)])
            a0 = a0 & 3
            a0 = a0 << 4
            a1 = int(self.h['_xea'][self.h['_bÌ']-1]) >> 4
            a = a0 | a1
            u0 =  int(self.h['_xea'][self.h['_bÌ']-1])
            u0 = u0 & 15
            u0 = u0 << 2
            u1 = int(self.h['_xea'][self.h['_bÌ']]) >> 6
            u =  u0 | u1
            c =  int(self.h['_xea'][self.h['_bÌ']]) & 63
            if self.isNaN(self.h['_xea'][(self.h['_bÌ'] - 1)]):
                u = c = 64
            else:
                c = 64 if self.isNaN(self.h['_xea'][self.h['_bÌ']])  else c
            i = butget(i ,y)
            a = butget(a,y)
            u = butget(u, y)
            c = butget(c, y)
            self.h['_bÌ'] -= 3
            p =  str(self.h["_xea"][i]) + str(self.h["_xea"][a]) + str(self.h["_xea"][u]) +str(self.h["_xea"][c])
            P +=p
            if  self.d['_bK'] > len(self.T) and P[-2:] == '99':
                P = P[0:-2] + '=='
        return '0ap' + P.replace('=','') + self.V[y]

class Create_list:
    sign_font = '4aacdb860103406394eb9ac78fbaa5a0v10j06L4LvHosWqjcBPDIbGCG2CPlMz63WfbdnMdDl4g4Aus8CyNdHAzaM7r5fYUXCw'
    A = {r'\ue78d': 0,
         r'\uec1a': 1,
         r'\ue574': 2,
         r'\uead3': 3,
         r'\uea62': 4,
         r'\ue724': 5,
         r'\ue646': 6,
         r'\ue624': 7,
         r'\uebd8': 8,
         r'\uec4f': 9
         }
    def __init__(self):
        self.total = []
        method_list = ['xt','wt','mt','kt','ct','pt',
                       'Et','At','Lt_qt','Nt','Bt','It',
                       'Jt','zt','Kt','Zt','Yt','Re',
                       ]

        self.StartTime = int(time.time()*1000)
        self.join_time = self.StartTime - 88124991#60985995#58066447#57678622
                                                    #1680013335716
                                                    #1680013012700
                                                    #1680013035544
                                                    #1680013002358
                                                    #1680013030090
                                                    #1680013011500
                                                    #1680013070433
        for method_name in method_list:
            attr = getattr(self,method_name)
            if method_name =='kt':
                self.total += attr("https://mms.pinduoduo.com/goods/goods_list")
            elif method_name == 'Jt':
                self.total += attr( "https://mms.pinduoduo.com/login/")
            else:
                self.total += attr()
        total_len = bin(len(self.total))[2:]
        totalLen = '0' * (16 - len(total_len)) + str(total_len)
        self.total = [3] + [1,0,0] + [int(totalLen[0:8],2),int(totalLen[8:16],2)] +self.total
        self.anti_content = PDD_Cracking().StartTask(self.total)
    def xt(self):
        clientX = random.randint(920,1280)
        clientY = random.randint(580,720)
        timeStampe = self.StartTime - self.join_time
        elementId = [0]
        self.randomSeedDict = {'clientX':  clientX, 'clientY': clientY, 'timeStampe':  timeStampe, 'elementId': 0}
        x =  [17] + int_to_bytes(clientX) + int_to_bytes(clientY) +  int_to_bytes(timeStampe) + elementId
        return  x
    def wt(self):
        similar_dicts_ = []
        timeStampe = self.StartTime - self.join_time - 100
        RandomRangeSeconds_Start =  timeStampe - 10000 if timeStampe - 10000 < 0 else 0
        RandomRangeSeconds_End   =  timeStampe - 100   if timeStampe - 10000 < 0 else 100
        while len(similar_dicts_) < 30:
            new_dict = copy.deepcopy(self.randomSeedDict)
            new_dict['clientX'] += random.randint(-10, 10)
            new_dict['clientY'] += random.randint(-10, 10)
            new_dict['timeStampe'] -= random.randint(RandomRangeSeconds_Start, RandomRangeSeconds_End)
            if set(new_dict.values()) not in [set(d.values()) for d in similar_dicts_]:
                similar_dicts_.append(new_dict)
        similar_dicts = sorted(similar_dicts_, key=lambda x: x['timeStampe'])
        similar_dicts[-2]['clientX'] = similar_dicts[-1]['clientX'] = self.randomSeedDict['clientX']
        similar_dicts[-2]['clientY'] = similar_dicts[-1]['clientY'] = self.randomSeedDict['clientY']
        bytesList = [200,30]
        for similar_dict in  similar_dicts:
            for dict_value in list(similar_dict.values()):
                bytesList +=  int_to_bytes(dict_value)
        return  bytesList
    def mt(self):
        new_dict = copy.deepcopy(self.randomSeedDict)
        for key in self.randomSeedDict.keys():
            if key == 'timeStampe':
                new_dict[key] += random.randint(1, 10)
        bytesList = [33]
        for dict_value in list(new_dict.values()):
            bytesList += int_to_bytes(dict_value)
        return  bytesList +[88,63,81,21]
    def kt(self,Api):
        return  [56]+[42]+[ord(A) for A in Api]+[0,143,132,104,71]
    def ct(self):

        return [64] + int_to_bytes(1920) + int_to_bytes(1040)
    def pt(self):
        random.seed(self.StartTime)
        random_folat = ["{:.16f}".format(random.random()) for i in range(2)]
        x_time = str(int(int(2**52+1) * float(random_folat[0]) + int(2**30+1) * float(random_folat[1]))) + '-' + str(self.StartTime)
        X = [ord(i) for  i in  x_time]
        return  [72] +  [len(X)] + X
    def Et(self):
        return [80, 128, 64]
    def At(self):
        return [88,205,168,34,218]
    def Lt_qt(self):
        return [97,121,105,121]
    def Nt(self):
        time_subtraction = int(time.time()*1000) - self.StartTime
        time_subtraction = time_subtraction if 20000 > time_subtraction > 1000  else random.randint(500,10000)
        n = 113 if time_subtraction<=255 else 114

        remainder_list = []
        while time_subtraction > 0:
            remainder = time_subtraction % 256
            remainder_list.append(remainder)
            time_subtraction //= 256
        remainder_list.reverse()
        return [n] + remainder_list
    def Bt(self):
        return [120,111] + [ord(i) for i in str("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36")]
    def It(self):
        return [128,40,88,112,69,56,108,48,84,89,108,112,67,89,88,48,84,98,88,84,95,82,73,106,85,102,106,88,50,110,103,49,112,77,120,70,83,106,95,76,95,77,136,40,88,112,69,56,108,48,84,89,108,112,67,89,88,48,84,98,88,84,95,82,73,106,85,102,106,88,50,110,103,49,112,77,120,70,83,106,95,76,95,77]
    def Jt(self,LoginApi):  #"https://mms.pinduoduo.com/login/"
        return []#[18*8] + [ord(i) for i in str(LoginApi)]
    def zt(self):
        return []#[169, 153]
        #
    def Kt(self):
        return [160,24] + [ord(i) for i in str("rBXNBGQEQyxjlkVHQCbqAg==")]
    def Zt(self):
                return  [170,1,249]
    def Yt(self):
        timestamp =  self.join_time
        binary_str = bin(timestamp)[2:]
        l = len(binary_str) // 6
        binary_str = '0' * (l * 8 - len(binary_str)) + str(binary_str)
        u = []
        for  c  in range(l):
            d = int(binary_str[c*8:(c+1)*8],2)
            u.append(d)
        return [182] + u
    def Re(self):
        return [208,0]


if __name__ == '__main__':
    Create_list = Create_list()
    print(Create_list.anti_content)


